package com.example.springevent.mockdata;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.springframework.util.Assert;

import com.example.springevent.ivd.domain.InvoiceVerifyDetail;
import com.google.common.collect.Lists;

public class IvdSampleData {

	private static List<InvoiceVerifyDetail> dataList = Lists.newArrayList();
	static {
		// 发票1对1
		dataList.add(new InvoiceVerifyDetail(1L, new BigDecimal(1), "Po001", 1L, "Code011", "No001", 1L, "A"));

		// 发票1对n
		dataList.add(new InvoiceVerifyDetail(2L, new BigDecimal(2), "Po002", 1L, "Code011", "No002", 1L, "A"));
		dataList.add(new InvoiceVerifyDetail(3L, new BigDecimal(4), "Po003", 1L, "Code011", "No002", 1L, "A"));

		// 发票n对1
		dataList.add(new InvoiceVerifyDetail(4L, new BigDecimal(8), "Po004", 1L, "Code001", "No003", 1L, "A"));
		dataList.add(new InvoiceVerifyDetail(5L, new BigDecimal(16), "Po004", 1L, "Code001", "No004", 1L, "A"));

		// 发票n对n
		dataList.add(new InvoiceVerifyDetail(6L, new BigDecimal(32), "Po005", 1L, "Code001", "No005", 1L, "A"));
		dataList.add(new InvoiceVerifyDetail(7L, new BigDecimal(64), "Po006", 1L, "Code001", "No005", 1L, "A"));
		dataList.add(new InvoiceVerifyDetail(8L, new BigDecimal(128), "Po006", 1L, "Code001", "No006", 1L, "A"));
		dataList.add(new InvoiceVerifyDetail(9L, new BigDecimal(256), "Po007", 1L, "Code001", "No006", 1L, "A"));
		dataList.add(new InvoiceVerifyDetail(10L, new BigDecimal(512), "Po007", 1L, "Code001", "No006", 1L, "D"));
	}

	public static List<InvoiceVerifyDetail> getDataList() {
		return dataList;
	}

	public synchronized static InvoiceVerifyDetail add(InvoiceVerifyDetail ivd) {
		Assert.notNull(ivd);
		Assert.notNull(ivd.getPkid());
		Assert.notNull(ivd.getVerifyAmt());
		Assert.hasText(ivd.getPoCode());
		Assert.hasText(ivd.getInvoiceNo());
		dataList.add(ivd);
		return ivd;
	}

	public synchronized static InvoiceVerifyDetail remove(InvoiceVerifyDetail ivd) {
		InvoiceVerifyDetail ret = null;
		Iterator<InvoiceVerifyDetail> iterator = dataList.iterator();
		while (iterator.hasNext()) {
			InvoiceVerifyDetail next = iterator.next();
			if (next.getPkid().equals(ivd.getPkid())) {
				ret = next;
				iterator.remove();
				break;
			}
		}
		return ret;
	}

}
